const jwt = require("jsonwebtoken");
const config = require("../../config");


function signToken(data) {
    return jwt.sign(data, config.jwt.secret, { expiresIn: config.jwt.expiresIn })
}

function verifyToken(token) {
    try {
        return {
            data: jwt.verify(token, config.jwt.secret),
            error: null
        }
    } catch (error) {
        return {
            data: null,
            error
        }
    }
}

module.exports = {
    signToken,
    verifyToken
}